import argparse
from pydub import AudioSegment
import os

input_folder="E:\project\maomao\english\Peppa_Pig"
output_folder="E:\project\maomao\english\peppa_pig_2"
os.makedirs(output_folder, exist_ok=True)
   
mp3_files = [file for file in os.listdir(input_folder) if file.endswith(".mp3")]
print("mp3_files")
for mp3_file in mp3_files:
        input_path = os.path.join(input_folder, mp3_file)
        output_path = os.path.join(output_folder, mp3_file)

        audio = AudioSegment.from_mp3(input_path)

        # 转换为128kbps，通过指定bitrate参数
        converted_audio = audio.set_frame_rate(44100).export(output_path, format="mp3", bitrate="128k")

print(f"转换完成，所有文件保存在 {output_folder} 文件夹中。")

# if __name__ == "__main__":
#     parser = argparse.ArgumentParser(description="Convert MP3 files in a folder to 128kbps.")
#     parser.add_argument("input_folder", help="Path to the input folder containing MP3 files.")
#     parser.add_argument("output_folder", help="Path to the output folder for converted MP3 files.")
    
#     args = parser.parse_args()

#     convert_to_128kbps(args.input_folder, args.output_folder)